#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 110, MOD = 1e9 + 7;

LL n, k;

struct matrix
{
	LL m[N][N];

	matrix()
	{
		memset(m, 0, sizeof m);
	}

	matrix operator*(const matrix& B)
	{
		matrix C;
		for(int i = 1;i <= n;i ++)
			for(int j = 1;j <= n;j ++)
				for(int k = 1;k <= n;k ++)
					C.m[i][j] = (C.m[i][j] + m[i][k] * B.m[k][j] % MOD) % MOD;
		return C;
	}
}A, RET;

void qpow(LL b)
{
	for(int i = 1;i <= n;i ++) RET.m[i][i] = 1;
	while(b)
	{
		if(b & 1) RET = RET * A;
		A = A * A;
		b >>= 1;
	}
}

int main()
{
	cin >> n >> k;
	for(int i = 1;i <= n;i ++)
		for(int j = 1;j <= n;j ++)
			cin >> A.m[i][j];
	qpow(k);
	for(int i = 1;i <= n;i ++)
	{
		for(int j = 1;j <= n;j ++) cout << RET.m[i][j] << " ";
		cout << endl;
	}
	return 0;
}